package ch.phovoz.tlog;




import java.util.Date;

import controller.DatabaseController;

import ch.phovoz.tlog.database.DatabaseManager;
import ch.phovoz.tlog.listener.TrainingSpinnerListener;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import android.os.Bundle;

import android.view.View;
import android.widget.SimpleCursorAdapter;
import android.widget.Spinner;
import android.widget.Toast;


public class TrainingActivity extends Activity {
	
	private SQLiteDatabase tdatabase;
	private Date datenow;
	private int currentExersiceID;
	private InfoObject infoobject;
	private DatabaseController dbc;

		
	
	  public void onCreate(Bundle savedInstanceState) {
		  infoobject= InfoObject.getInfoObject();
		  dbc=new DatabaseController(this);
		  
		  DatabaseManager dbmanager= new DatabaseManager(this);
		  tdatabase=dbmanager.getWritableDatabase();

	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.training);
	        Cursor ExersiceCursor = tdatabase.rawQuery("SELECT * FROM "+DatabaseManager.TABLE_EXERSICENAME +";", null);
			startManagingCursor(ExersiceCursor);
	        
	        
	        Spinner spinner = (Spinner) findViewById(R.id.spinner1);
	       
	        
	        SimpleCursorAdapter exersiceAdapter=
					new SimpleCursorAdapter(this,
							android.R.layout.simple_list_item_1,
							ExersiceCursor,
							new String[]{"name"},
							new int[]{android.R.id.text1});
	        exersiceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
	        spinner.setAdapter(exersiceAdapter);        
	        spinner.setOnItemSelectedListener(new TrainingSpinnerListener(this));
	    
	        tdatabase.close();
	  	  
	  	  	    }
	 
	 

	   public void onNewExersiceklick(View view){
		
		dbc.StartExersice();
		   
	    	switch (view.getId()){
	    	case R.id.startExersice:
	    		startActivity(new Intent(this, Exersice.class));
	    		
	    		break;
	    	
	    	}
	    }

	 
}
